package com.im.common.toolkit;

import java.util.Collection;
import java.util.Map;

/**
 * @author gongym
 * @date 2019/1/11 10:17
 */
public class CommonUtils {

  public static boolean isEmpty(final Object params) {
    return !isNotEmpty(params);
  }

  public static boolean isNotEmpty(final Object params) {
    if (null != params) {
      if (params instanceof Map) {
        Map<?, ?> map = (Map) params;
        return !map.isEmpty();
      } else if (params instanceof Collection) {
        Collection<?> coll = (Collection) params;
        return !coll.isEmpty();
      } else if (params instanceof CharSequence) {
        CharSequence cs = (CharSequence) params;
        int strLen;
        if ((strLen = cs.length()) == 0) {
          return false;
        }
        for (int i = 0; i < strLen; i++) {
          if (Character.isWhitespace(cs.charAt(i))) {
            return false;
          }
        }
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
}
